import { Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
const OSS = require('ali-oss')
@Injectable()
export class AliossService {
    private ossClient:typeof OSS|null = null
    constructor(private configService : ConfigService) {
        let ossConfig = this.configService.get('alioss')
        this.ossClient = new OSS({
            accessKeyId : ossConfig.accessKeyId,
            accessKeySecret : ossConfig.accessKeySecret,
            region : ossConfig.region,
        })
    }

    async bucketisExist(bucketName:string) {
        try {
            const result = await this.ossClient.getBucketInfo(bucketName)
            return true
        } catch (error) {
            return false
        }
    }
}
